﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Upsam.RopaOnline.Modelo.Common;

namespace Upsam.RopaOnline.Web
{
	public partial class StreetTypeManagement : System.Web.UI.Page
	{
		private const string PAGE_NAME = "StreetTypeManagement.aspx";
		private const string SEARCH_PAGE_NAME = "StreetTypeSearch.aspx";
		
		protected void Page_Load( object sender, EventArgs e )
		{
			ConfigPageMode();
		}

		protected void fvwStreetType_ItemCommand( object sender, FormViewCommandEventArgs e )
		{
			if( e.CommandName.Equals( ConstantsEnums.CancelCommand ) )
				Response.Redirect( SEARCH_PAGE_NAME, false );
		}

		private void ConfigPageMode()
		{
			string pageMode = Request.QueryString[ConstantsEnums.QueryStringKeyPageMode];
			if( !string.IsNullOrEmpty( pageMode ) )
			{
				PageMode pageModeEnum = (PageMode)Enum.Parse( typeof( PageMode ), pageMode, true );
				switch( pageModeEnum )
				{
					case PageMode.EditMode:
						fvwStreetType.ChangeMode( FormViewMode.Edit );
						break;
					case PageMode.InsertMode:
						fvwStreetType.ChangeMode( FormViewMode.Insert );
						break;
					default:
						fvwStreetType.ChangeMode( FormViewMode.ReadOnly );
						break;
				}
			}
		}

		protected void fvwStreetType_ItemUpdated( object sender, FormViewUpdatedEventArgs e )
		{
			Response.Redirect( SEARCH_PAGE_NAME, false );
		}

		protected void fvwStreetType_ItemInserted( object sender, FormViewInsertedEventArgs e )
		{
			Response.Redirect( SEARCH_PAGE_NAME, false );
		}
	}
}
